/*
 * Copyright (C) 2011-2012 Adam Gregoire <bsdunx@gmail.com>
 * Copyright (C) 2011-2012 Jeff Hubbard <lord2800@gmail.com>
 *
 * This file is part of the ScriptKit scripting engine library.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#ifndef __JSAPI_EXT_UTIL_HPP__
#define __JSAPI_EXT_UTIL_HPP__ 1

#include "jsapi.h"

/* Various macros to make JSAPI a bit easier to work with */

#define JS_PS(name, id, flags, getter, setter) \
	{name, id, flags, getter, setter}

#define JS_PS_END JS_PS(0, 0, 0, 0, 0)

#define JS_CS(classp, proto, ctor, argc, methods, props, static_methods, static_props) \
	{classp, proto, ctor, argc, methods, props, static_methods, static_props}

#define JS_CS_END {0, 0, 0, 0, 0, 0, 0, 0}

#define JS_MS(name, classes, static_methods, static_properties) \
	{name, classes, static_methods, static_properties}

#define JS_MS_END {0, 0, 0, 0}

#define JSCLASS_SPEC(add, del, get, set, enumerate, resolve, convert, ctor) \
	add, del, get, set, enumerate, resolve, convert, \
	nullptr, nullptr, nullptr, ctor, nullptr, nullptr, nullptr

#define JSCLASS_DEFAULT_WITH_CTOR(ctor) \
	JSCLASS_SPEC(JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, ctor)

#define JSCLASS_DEFAULT_STANDARD_MEMBERS \
	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, \
	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, \
	JSCLASS_NO_OPTIONAL_MEMBERS

#define JSPROP_DEFAULT	JSPROP_ENUMERATE|JSPROP_PERMANENT
#define JSPROP_STATIC	JSPROP_ENUMERATE|JSPROP_PERMANENT|JSPROP_READONLY

#define JSAPI_FUNC(name) JSBool name(JSContext *cx, unsigned argc, jsval *vp)
#define JSAPI_EMPTY_CTOR(name) JSBool name(JSContext* cx, unsigned argc, jsval* vp)
#define JSAPI_EMPTY_CTOR_BODY(name) JSBool name(JSContext* cx, unsigned argc, jsval* vp) { return JS_ThrowError(cx, #name " is not constructable."); }
#define JSAPI_PROP(name) JSBool name(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
#define JSAPI_STRICT_PROP(name) JSBool name(JSContext* cx, JSObject *obj, jsid id, JSBool strict, jsval* vp)

#endif /* __JSAPI_EXT_UTIL_HPP__ */

